import React from "react";
import cover from "../images/demo/1.jpg";
export default class ArticleBody extends React.Component {

    constructor(...props) {
        super(...props);
        this.state = {
            news: null
        }
    }

    componentDidMount() {
        $.get('/api/news/view', {
            id: this.props.id
        }, (news)=> {
            this.setState({news});
        }, 'json');
    }

    componentWillReceiveProps(props) {
        if (props.id) {
            $.get('/api/news/view', {
                id: props.id
            }, (news)=> {
                this.setState({news});
            }, 'json');
        }
    }

    render() {
        return this.state.news ? (
            <div className="news">
                {/*<h1 className="title">{this.state.news.title}</h1>*/}
                {/*<div className="date">{this.state.news.createdAt}</div>*/}
                <div className="content" dangerouslySetInnerHTML={{__html: this.state.news.content}}>
                </div>
            </div>
        ) : <p style={{padding:'2rem',textAlign:'center'}}>读取中</p>;
    }
}
ArticleBody.propTypes = {
    id: React.PropTypes.number.isRequired
};